<script setup>
import { ref } from 'vue'
import axios from 'axios'
const list = ref([])

const getList = async () => {
  const r = await axios.get('/list')
  list.value = r.data
}

getList()

const delItem = async (id) => {
  await axios.delete(`del?id=${id}`)
  getList()
}

const handleDel = (id) => delItem(id);
</script>

<template>
  <div class="app">
    <el-table :data="list">
      <el-table-column label="ID" prop="id"></el-table-column>
      <el-table-column label="姓名" width="150" prop="name"></el-table-column>
      <el-table-column label="籍贯" prop="place"></el-table-column>
      <el-table-column label="操作" width="100">
        <!-- Vue3 如果写了 template，必须要加 # 号 -->
        <template #default="scope">
          <el-button type="primary" link @click="handleDel(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<style>
.app {
  width: 980px;
  margin: 100px auto 0;
}
</style>